public class BinarySearchTest {
    public static void main(String[] args) {
        BinarySearchTest binarySearchTest = new BinarySearchTest();
        long start = 0;
        long end = 10000000000000000L;
        long target =9566447;
        long s1 = System.currentTimeMillis();

        System.out.println(binarySearchTest.BinarySearch(start,end,target));

        long s2 =System.currentTimeMillis();
        System.out.println(s2-s1);

        long s3 = System.currentTimeMillis();
        System.out.println(binarySearchTest.search(start,end,target));
        long s4 =System.currentTimeMillis();
        System.out.println(s4 -s3);

    }
    public long search(long start, long end, long target) {
        /*long mid = (start+ end)/2;*/

        for (long i = start; i < end+1; i++) {
            if (i == target){
                return i;
            }
        }
        return 0;
    }

    public long BinarySearch(long start, long end, long target) {
        /*long mid = (start+ end)/2;*/

        while (start + 1 < end) {
            long mid = start + (end - start) / 2;
            if (target == mid){
                return target;
            }
            if (target < mid){
                end = mid;
            }
            if (target>mid){
                start=mid;
            }
        }
        if (start == target || end ==target){
            return target;
        }
        return 0;
    }
}
